<?php
class Classification extends CI_Controller{

	//获取所有分类
	function select(){
		$page = $_GET["page"];
		$limit = $_GET["limit"];
		$this->load->model('server/news_model');
		$cont = [
			'table' => 'classification',
			'limit' => [($page - 1) * $limit, $limit]
		];
		$data = $this->news_model->select_form($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}

	//添加数据
	function add(){
		$id = $_GET["id"];
		$name = $_GET["fenglei_name"];
		$this->load->model('server/news_model');
		$cont = [
			'table' => 'classification',
			'data'=>[
				'id'=>$id,
				'name'=>$name
			]
		];
		$data = $this->news_model->insert_one($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}

	//删除id号
	function delete(){
		$id = $_GET["id"];
		$this->load->model('server/news_model');
		$cont = [
			'table' => 'classification',
			'where'=>[
				'id'=>$id
			]
		];
		$data = $this->news_model->delete($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}

	//更新
	function up(){
		$id = $_GET["id"];
		$name = $_GET["fenglei_name"];
		$this->load->model('server/news_model');
		$cont = [
			'table' => 'classification',
			'data'=>[
				'id'=>$id,
				'name'=>$name
			]
		];
		$data = $this->news_model->replace($cont);
		echo json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;
	}
}
